package cn.wolfcode.trip.api.controller;

import cn.wolfcode.trip.base.domain.StrategyDetail;
import cn.wolfcode.trip.base.domain.Travel;
import cn.wolfcode.trip.base.domain.TravelContent;
import cn.wolfcode.trip.base.query.QueryObject;
import cn.wolfcode.trip.base.query.SearchQueryObject;
import cn.wolfcode.trip.base.service.ISearchService;
import cn.wolfcode.trip.base.service.IStrategyDetailService;
import cn.wolfcode.trip.base.service.ITravelService;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 搜索 资源控制器
 */
@RestController
@RequestMapping("Search")
public class SearchController {

    @Autowired
    private ISearchService searchService;

    /**
     * 获取
     * 请求路径  /Search
     * 请求方式  get
     * 请求参数  QueryObject
     * 返回结果  PageInfo
     *
     */
    @GetMapping
    @RequestMapping("/queryStrategy")
    public PageInfo query(SearchQueryObject qo) {
        PageInfo pageInfo = searchService.query(qo);
        return pageInfo;
    }

    @GetMapping
    @RequestMapping("/queryTravel")
    public PageInfo query2(SearchQueryObject qo) {
        PageInfo pageInfo = searchService.query2(qo);
        return pageInfo;
    }


    @Autowired
    private IStrategyDetailService detailService;
    /**
     * 根据攻略文章id查询文章对象
     * 1.资源 /strategyDetails/{id}
     * 2.请求方式 get
     * 3.请求参数 路径占位符
     * 4.返回结果 StrategyDetail
     */
    @GetMapping("{id}")
    public StrategyDetail getById(@PathVariable Long id){
        return detailService.getById(id);
    }

    @Autowired
    private ITravelService travelService;

    /**
     * 根据id获取游记对象的接口
     * 请求路径  /travels/{id}
     * 请求方式  get
     * 请求参数  Long id
     * 返回结果  游记对象
     */
    @GetMapping("{id}/travelContentGetById")
    public Travel getById2(@PathVariable Long id) {
        return travelService.getById(id);
    }

}
